import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/:pathMatch(.*)*', // 捕获未匹配路由
      name: '404NotFound',
      component: () => import('@/views/404NotFound/index.vue'),
      meta: {
        title: '404 Not Found'
      }
    }
  ]
})

router.beforeEach((to, _from, next) => {
  // 动态标题替换
  document.title = to.meta.title
    ? to.meta.title + ' - ' + import.meta.env.VITE_APP_TITLE
    : import.meta.env.VITE_APP_TITLE
  next()
})

export default router
